# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sexpp
pkgver=0.8.8
pkgrel=0
pkgdesc="S-Expressions parser and generator library in C++"
url="https://github.com/rnpgp/sexpp"
arch="all"
license="MIT"
makedepends="cmake samurai"
checkdepends="gtest-dev"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-cli
	"
source="https://github.com/rnpgp/sexpp/archive/v$pkgver/sexpp-$pkgver.tar.gz"

build() {
	_build build-shared -DBUILD_SHARED_LIBS=ON
	_build build-static -DBUILD_SHARED_LIBS=OFF
}

_build() {
	local outdir="$1"; shift

	local crossopts=
	[ "$CBUILD" != "$CHOST" ] \
		&& crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"

	cmake -B "$outdir" -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DDOWNLOAD_GTEST=OFF \
		-DWITH_SEXP_CLI=ON \
		-DWITH_SEXP_TESTS="$(want_check && echo ON || echo OFF)" \
		$crossopts \
		"$@"
	cmake --build "$outdir"
}

check() {
	ctest --test-dir build-shared --output-on-failure
}

package() {
	DESTDIR="$pkgdir" cmake --install build-static
	DESTDIR="$pkgdir" cmake --install build-shared
}

cli() {
	pkgdesc="S-Expressions parser and generator utility"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/bin
}

sha512sums="
27660ebf1516539ab55cfe67d7636f34ce57439626b279f42465638f64791c20debc9c7dd28e5c84afb75377365640eae8cffd9d1b1378946435478adb403fad  sexpp-0.8.8.tar.gz
"
